import { create } from "zustand";
import { login } from "../api/user_api";
import { setToken, getToken, removeToken } from "../utils/token";
const userLoginStore = create((set) => ({
  token: "",
  login: async (userForm) => {
    login(userForm).then((res) => {
      if (res.code === 200) {
        setToken(res.data.token);
      } else {
        throw new Error(res.msg);
      }
    });
  },
  logout: () => {
    removeToken();
  },
}));
export default userLoginStore;
